<?php defined('IN_NWIDC') or exit('Access Invalid!');?>
<style>
    tr th.bdl{
        border-left:1px solid #e6e6e6;
    }
    thead tr th{
        text-align: center;
    }
</style>
<div class="tabmenu">
    <?php include template('layout/submenu');?>
</div>

<script src="/packages/excel_import_export/cmay.js"></script>
<script>
    var mdata = {
        success : [],
        failed : []
    }
</script>

<div c-tpl="mdata" class="layertips" style="display: none;">
    <h2>
        导出成功,数量{success.length}
    </h2>
    {each item in success}
    <p>
        {item}
    </p>
    {end}
    <hr>
    <h2>
        导出失败,数量{failed.length}
    </h2>
    {each item in $data.failed}
    <p>
        {item[0]} : {item[1]}
    </p>
    {end}
</div>
<script>
    var impcallback = function(data){
        if(data.errcode != 0) return layer.msg("导处失败");
        mdata.success = data.errmsg.success;
        mdata.failed = data.errmsg.failed;
        $('.layertips').show();
        if(data.errmsg.file){
            $('.downlink').show();
            $('.downlink a').attr("href",data.errmsg.file).click();
        }
    };
</script>
<script>
    $(".ckall").click(function () {
        $('.chks').prop('checked',this.checked)
    });

    $(".btn.export").click(function () {
        var ids = $('.chks:checked').toArray().map(function (item) {
            return item.value;
        });
//        if(ids.length == 0){
//            return layer.msg("请先选择订单");
//        }
        var form = $('#form1');
        var input1=$("<input>");
        input1.attr("type","hidden");
        input1.attr("name","export");
        input1.attr("value",'y');
        form.append(input1);
        form.submit();
        input1.attr("value",'n');
    });
</script>
<form method="get" action="index.php" target="_self" id="form1">
    <table class="search-form">
        <input type="hidden" name="act" value="store_order" />
        <input type="hidden" name="op" value="index_detail" />
        <?php if ($_GET['state_type']) { ?>
            <input type="hidden" name="state_type" value="<?php echo $_GET['state_type']; ?>" />
        <?php } ?>

        <tr>
            <td>&nbsp;</td>
            <td>
                订单状态
            </td>
            <td>
                <select name="super_order_state" id="">
                    <option value="-1">所有</option>
                    <option value="10" <?php if($_GET['super_order_state'] == 10) echo 'selected';?>>未付款</option>
                    <option value="20" <?php if($_GET['super_order_state'] == 20) echo 'selected';?>>已付款</option>
                    <option value="30" <?php if($_GET['super_order_state'] == 30) echo 'selected';?>>已发货</option>
                    <option value="40" <?php if($_GET['super_order_state'] == 40) echo 'selected';?>>已收货</option>
                </select>
            </td>

            <th><?php echo $lang['store_order_add_time'];?></th>
            <td class="w240"><input type="text" class="text w70" name="query_start_date" id="query_start_date" value="<?php echo $_GET['query_start_date']; ?>" /><label class="add-on"><i class="icon-calendar"></i></label>&nbsp;&#8211;&nbsp;<input id="query_end_date" class="text w70" type="text" name="query_end_date" value="<?php echo $_GET['query_end_date']; ?>" /><label class="add-on"><i class="icon-calendar"></i></label></td>
            <th><?php echo $lang['store_order_buyer'];?></th>
            <td class="w100"><input type="text" class="text w80" name="buyer_name" value="<?php echo $_GET['buyer_name']; ?>" /></td>
            <th><?php echo $lang['store_order_order_sn'];?></th>
            <td class="w160"><input type="text" class="text w150" name="order_sn" value="<?php echo $_GET['order_sn']; ?>" /></td>
            <td class="w70 tc"><label class="submit-border">
                    <input type="submit" class="submit" value="<?php echo $lang['store_order_search'];?>" />
                </label></td>
        </tr>
    </table>
</form>
<div class="search-form">
    <div style="padding: 10px;">
        <a href="javascript:;"  class="ncsc-btn ncsc-btn-orange export"title="大于200条数据时只导出前200条;">导出</a>
    </div>
</div>
<div id="tabletitle" style="width:959px; height:35px; overflow-x:scroll;overflow-y: hidden;">
    <table style="width:4320px; height:300px; text-align:center">
        <thead>
        <tr>
            <th class="w10"></th>

            <th class="bdl w100">商品货号</th>
            <th class="bdl w340" style="text-align:left;text-indent: 2em;">商品名称</th>
            <th class="bdl w110">条形码</th>
            <th class="bdl w100">总金额</th>
            <th class="bdl w100">商品单价</th>
            <th class="bdl w120">商品数量</th>

            <th class="w120 bdl">用户名</th>
            <th class="w60 bdl">用户ID</th>

            <th class="bdl w150">收货人姓名</th>
            <th class="bdl w100"  style="border-left:2px solid #f90;">收货人电话</th>

            <th class="bdl w530">收货人地址</th>

            <th class="bdl w150">支付时间</th>
            <th class="bdl w90">支付方式</th>
            <th class="bdl w150">支付单号</th>
            <th class="bdl w60">订单状态</th>
            <th class="bdl w150">发货时间</th>

            <th class="bdl w60">送货方式</th>
            <th class="w180" style="border-left:2px solid #f00;">快递单号</th>
            <th class="bdl w200">商家名称</th>
            <th class="bdl w65">商家ID</th>

            <th class="bdl w50">运费</th>
            <th class="bdl w50">税费</th>
            <th class="w50" style="border-left:2px solid #c00;">预存款</th>
            <th class="bdl w50">代金券</th>
            <th class="bdl w150">实际支付金额</th>

            <th class="bdl w50">佣金比例</th>
            <th class="bdl w50">佣金金额</th>
            <th class="bdl w150">签收时间</th>
            <th class="bdl w50">是否开票</th>
            <th class="bdl w150">发票抬头</th>

            <th class="bdl">备注</th>
        </tr>
        </thead>
    </table>
</div>

<div  class="order-list-detail" id="tablebody" style="width:959px; height:500px; overflow:scroll;">
    <table class="ncsc-default-table order" style="width:4300px; max-height:700px; text-align:center">
        <?php if (is_array($output['order_list']) and !empty($output['order_list'])) { ?>
        <?php foreach($output['order_list'] as $order_id => $order) { ?>
        <tbody>

        <tr>
            <td colspan="20" class="sep-row"></td>
        </tr>
        <tr>
            <th colspan="100">
            <span class="ml10" style="min-width: 220px">
                <?php echo $lang['store_order_order_sn'].$lang['nc_colon'];?><em><?php echo $order['order_sn']; ?></em>
            </span>
                <span class="ml10" style="min-width: 160px">买家：<?php echo $order['buyer_name'];?> </span>
                <span class="ml10">订单总额：<?php echo $order['order_amount']; ?></span>
                <span class="ml10">订单状态：<?php echo $order['state_desc']; ?> </span>
                <?php if ($order['is_we_groupbuy'] > 0) {
                    echo '<span class="ml10" style="color:#f60">(微团订单)</span>';
                } ?>
                <span><?php echo $lang['store_order_add_time'].$lang['nc_colon'];?><em class="goods-time"><?php echo date("Y-m-d H:i:s",$order['add_time']); ?></em></span>
            </td>

            </th>
        </tr>
        <?php $i = 0;?>
        <?php if(!$order['goods_list'])
            $order['goods_list'] = [];
        foreach($order['goods_list'] as $k => $goods) {
            ?>
            <?php $i++;?>
            <tr>
                <td class="w10"></td>

                <td class="bdl w100"><?php echo $goods['gdetailinfo']['goods_serial'];?></td>
                <td class="bdl w340" style="text-align:left;text-indent: 2em;"><?php echo $goods['goods_name']; ?></td>
                <td class="bdl w110"><?php echo $goods['gdetailinfo']['sharp'];?></td>
                <td class="bdl w100"><?php echo $goods['goods_price']*$goods['goods_num']; ?></td>
                <td class="bdl w100"><?php echo $goods['goods_price']; ?></td>
                <td class="bdl w120"><?php echo $goods['goods_num']; ?></td>

                <?php if (($order['goods_count'] > 1 && $k ==0) || ($order['goods_count']) == 1){ ?>

                    <td rowspan="<?php echo $order['goods_count'];?>" class="w120 bdl"><?php echo $order['buyer_name']?></td>
                    <td rowspan="<?php echo $order['goods_count'];?>" class="w60 bdl"><?php echo $order['buyer_id']?></td>

                    <td rowspan="<?php echo $order['goods_count'];?>" class="bdl w150"><?php echo $order['receiver_name']?></td>
                    <td rowspan="<?php echo $order['goods_count'];?>" class="bdl w100" style="border-left:2px solid #f90;"><?php echo $order['phone']?></td>
                    <td rowspan="<?php echo $order['goods_count'];?>" class="bdl w530"><?php echo $order['address']?></td>

                    <td rowspan="<?php echo $order['goods_count'];?>" class="bdl w150"><?php echo date("Y-m-d H:m:s",$order['payment_time'])?></td>
                    <td rowspan="<?php echo $order['goods_count'];?>" class="bdl w90"><?php echo $order['payment_code'];?></td>
                    <td rowspan="<?php echo $order['goods_count'];?>" class="bdl w150"><?php echo $order['pay_sn'];?></td><!--支付单号-->
                    <td rowspan="<?php echo $order['goods_count'];?>" class="bdl w60"><?php echo $order['order_state'];?></td><!--订单状态-->
                    <td rowspan="<?php echo $order['goods_count'];?>" class="bdl w150"><?php echo date("Y-m-d H:m:s",$order['ocominfo']['shipping_time']);?></td><!--发货时间-->
                    <td rowspan="<?php echo $order['goods_count'];?>" class="bdl w60"><?php echo $order['ocominfo']['shipping_express_id']?></td><!--送货方式--><!-- -->
                    <td rowspan="<?php echo $order['goods_count'];?>" class="w180" style="border-left:2px solid #f00;"><?php echo $order['shipping_code'];?></td><!--快递单号-->
                    <td rowspan="<?php echo $order['goods_count'];?>" class="bdl w200"><?php echo $order['store_name'];?></td><!--商家名称-->
                    <td rowspan="<?php echo $order['goods_count'];?>" class="bdl w65"><?php echo $order['store_id'];?></td>

                    <td rowspan="<?php echo $order['goods_count'];?>" class="bdl w50"><?php echo $order['shipping_fee']?></td><!--运费-->
                    <td rowspan="<?php echo $order['goods_count'];?>" class="bdl w50"><?php echo $order['order_tax']?></td><!--税费-->
                    <td rowspan="<?php echo $order['goods_count'];?>" class="w50" style="border-left:2px solid #c00;"><?php echo $order['pd_amount']?></td><!--预存款-->
                    <td rowspan="<?php echo $order['goods_count'];?>" class="bdl w50"><?php echo $order['rcb_amount']?></td><!--代金券-->
                    <td rowspan="<?php echo $order['goods_count'];?>" class="bdl w150"><?php echo $order['order_amount']-$order['pd_amount']-$order['rcb_amount'];?></td><!--实际支付金额-->
                    <td rowspan="<?php echo $order['goods_count'];?>" class="bdl w50"><?php echo $order['distribute_rate']?$order['distribute_rate']:'0';?></td><!--佣金比例-->
                    <td rowspan="<?php echo $order['goods_count'];?>" class="bdl w50"><?php echo $order['distribute_price']?$order['distribute_price']:'0';?></td><!--佣金金额-->
                    <td rowspan="<?php echo $order['goods_count'];?>" class="bdl w150"><?php echo $order['finnshed_time']?$order['finnshed_time']:'无';?></td><!--签收时间-->
                    <td rowspan="<?php echo $order['goods_count'];?>" class="bdl w50"><?php echo $order['inv_info']['抬头']?'是':'否';?></td><!--是否开票-->
                    <td rowspan="<?php echo $order['goods_count'];?>" class="bdl w150"><?php echo $order['inv_info']['抬头']?></td><!--发票抬头-->
                    <td rowspan="<?php echo $order['goods_count'];?>" class="bdl"><?php echo $order['ocominfo']['deliver_explain']?$order['ocominfo']['deliver_explain']:'无';?></td><!--备注-->

                <?php } ?>

            </tr>
        <?php }?>
        <?php } } else { ?>
            <tr>
                <td colspan="20" class="norecord"><div class="warning-option"><i class="icon-warning-sign"></i><span><?php echo $lang['no_record'];?></span></div></td>
            </tr>
        <?php } ?>
        </tbody>

    </table>
</div>
<table style="width:1000px;text-align: center">
    <tfoot>
    <?php if (is_array($output['order_list']) and !empty($output['order_list'])) { ?>
        <tr>
            <td colspan="20"><div class="pagination"><?php echo $output['show_page']; ?></div></td>
        </tr>
    <?php } ?>
    </tfoot>
</table>

<script src="/packages/resource/laydate/laydate.js"></script>
<script>
    var start = {
        elem: '#query_start_date',
        format: 'YYYY/MM/DD hh:mm:ss',
        istime: true,
        istoday: false,
        choose: function () {
            $('#start_time').trigger('blur');
        }
    };
    var end = {
        elem: '#query_end_date',
        format: 'YYYY/MM/DD hh:mm:ss',
        istime: true,
        istoday: false,
        choose: function () {
            $('#end_time').trigger('blur');
        }
    };
    laydate(start);
    laydate(end);
</script>

<script type="text/javascript">
    $(function(){
        $('.checkall_s').click(function(){
            var if_check = $(this).attr('checked');
            $('.checkitem').each(function(){
                if(!this.disabled)
                {
                    $(this).attr('checked', if_check);
                }
            });
            $('.checkall_s').attr('checked', if_check);
        });
        $('#skip_off').click(function(){
            url = location.href.replace(/&skip_off=\d*/g,'');
            window.location.href = url + '&skip_off=' + ($('#skip_off').attr('checked') ? '1' : '0');
        });


        $('#tabletitle').scroll(function(){
            $('#tablebody').scrollLeft($('#tabletitle').scrollLeft());
        });
        $('#tablebody').scroll(function(){
            $('#tabletitle').scrollLeft($('#tablebody').scrollLeft());
        });
    });
</script>
